<!-- $Id: agency_info.htm 14216 2008-03-10 02:27:21Z testyang $ -->

{include file="pageheader.htm"}
{insert_scripts files="validator.js,../js/transport.js,../js/region.js"}
<div class="main-div">
    <form method="post" action="agency.php" name="theForm" enctype="multipart/form-data" onsubmit="return validate()">
        <table cellspacing="1" cellpadding="3" width="100%">
            <tr>
                <td class="label">{$lang.label_agency_name}</td>
                <td><input type="text" name="agency_name" maxlength="60" value="{$agency.agency_name}" />
                    {$lang.require_field}</td>
            </tr>
            <tr>
                <td class="label">联系人：</td>
                <td><input type="text" name="linkman" value="{$agency.linkman}" /></td>
            </tr>
            <tr>
                <td class="label">固定电话：</td>
                <td><input type="text" name="phone" value="{$agency.phone}" /></td>
            </tr>
            <tr>
                <td class="label">手机：</td>
                <td><input type="text" name="mobile_phone" value="{$agency.mobile_phone}" /></td>
            </tr>
            <tr>
                <td class="label">地址：</td>
                <td><input type="text" name="address" value="{$agency.address}" /></td>
            </tr>
  			<tr>
                <td class="label">区域：</td>
                <td><input type="text" name="region_desc" value="{$agency.region_desc}" /></td>
            </tr>            
            <tr>
                <td class="label">邮编：</td>
                <td><input type="text" name="zipcode" value="{$agency.zipcode}" /></td>
            </tr>
            <tr>
                <td class="label">营业时间：</td>
                <td><input type="text" name="shop_hours" value="{$agency.shop_hours}" /></td>
            </tr>
            <tr>
                <td class="label">{$lang.label_agency_desc}</td>
                <td><textarea  name="agency_desc" cols="60" rows="4"  >{$agency.agency_desc}</textarea></td>
            </tr>
            <tr>
                <td class="label">
					<a href="javascript:showNotice('noticeAdmins');" title="{$lang.form_notice}">
					<img src="images/notice.gif" width="16" height="16" border="0" alt="{$lang.form_notice}"></a>{$lang.label_admins}</td>
                <td>
					登录名:<input type="text" style="width:100px;" id="user_name"/>
					<select id="role">
						<option value="0">请选择角色...</option>
						{foreach from=$role_list item=role}
						<option value="{$role.role_id}">{$role.role_name}</option>
						{/foreach}
					</select>
					<input type="button" class="button" name="search" value=" 搜索 " onclick="search_admin();">
					<select id="search_admin_list"></select>
					<input type="button" class="button" value="+" onclick="add_admin();">
					<div id="agency_admin_list">
						{foreach from=$agency.admin_list item=admin}
							<input type="checkbox" name="admins[]" value="{$admin.user_id}" checked="checked" />{$admin.user_name}&nbsp;&nbsp;
						{/foreach}
					</div>
					<br />
                    <span class="notice-span" {if $help_open}style="display:block" {else} style="display:none" {/if} id="noticeAdmins">{$lang.notice_admins}</span></td>
            </tr>
            <tr>
                <td class="label">{$lang.label_regions}</td>
                <td id="regionCell">{foreach from=$agency.region_list item=region}
                    <input type="checkbox" name="regions[]" value="{$region.region_id}" checked="true" />
                    {$region.region_name}&nbsp;&nbsp;
                    {/foreach} </td>
            </tr>
        </table>
        <hr>
        <table cellspacing="1" cellpadding="3" width="100%">
            <caption>
            <strong>{$lang.add_region}</strong>
            </caption>
            <tr>
                <td width="10%">&nbsp;</td>
                <td>{$lang.label_country}</td>
                <td>{$lang.label_province}</td>
                <td>{$lang.label_city}</td>
                <td>{$lang.label_district}</td>
                <td width="10">&nbsp;</td>
                <td width="10%">&nbsp;</td>
            </tr>
            <tr>
                <td>&nbsp;</td>
                <td><select name="country" id="selCountries" onChange="region.changed(this, 1, 'selProvinces')" size="10">
                        
                        
      {foreach from=$countries item=country name="fe_country"}
        
                        
                        <option value="{$country.region_id}" {if $smarty.foreach.fe_country.first}selected{/if}>{$country.region_name|escape:html}</option>
                        
                        
      {/foreach}
    
                    
                    </select></td>
                <td><select name="province" id="selProvinces" onChange="region.changed(this, 2, 'selCities')" size="10">
                        <option value="">{$lang.select_please}</option>
                    </select></td>
                <td><select name="city" id="selCities" onChange="region.changed(this, 3, 'selDistricts')" size="10">
                        <option value="">{$lang.select_please}</option>
                    </select></td>
                <td><select name="district" id="selDistricts" size="10">
                        <option value="">{$lang.select_please}</option>
                    </select></td>
                <td><input type="button" value="+" class="button" onclick="addRegion()" /></td>
                <td>&nbsp;</td>
            </tr>
        </table>
        <table align="center">
            <tr>
                <td colspan="2" align="center"><input type="submit" class="button" value="{$lang.button_submit}" />
                    <input type="reset" class="button" value="{$lang.button_reset}" />
                    <input type="hidden" name="act" value="{$form_action}" />
                    <input type="hidden" name="id" value="{$agency.agency_id}" /></td>
            </tr>
        </table>
    </form>
</div>
{insert_scripts files="../js/utils.js,validator.js"}
{literal}
<script language="JavaScript">
<!--
region.isAdmin = true;
document.forms['theForm'].elements['agency_name'].focus();
onload = function()
{
    var selCountry = document.forms['theForm'].elements['country'];
    if (selCountry.selectedIndex >= 0)
    {
        region.loadProvinces(selCountry.options[selCountry.selectedIndex].value);
    }
    // 开始检查订单
    startCheckOrder();
}
/**
 * 检查表单输入的数据
 */
function validate()
{
    validator = new Validator("theForm");
    validator.required("agency_name",  no_agencyname);
    return validator.passed();
}

/**
 * 添加一个区域
 */
function addRegion()
{
    var selCountry  = document.forms['theForm'].elements['country'];
    var selProvince = document.forms['theForm'].elements['province'];
    var selCity     = document.forms['theForm'].elements['city'];
    var selDistrict = document.forms['theForm'].elements['district'];
    var regionCell  = document.getElementById("regionCell");

    if (selDistrict.selectedIndex > 0)
    {
        regionId = selDistrict.options[selDistrict.selectedIndex].value;
        regionName = selDistrict.options[selDistrict.selectedIndex].text;
    }
    else
    {
        if (selCity.selectedIndex > 0)
        {
            regionId = selCity.options[selCity.selectedIndex].value;
            regionName = selCity.options[selCity.selectedIndex].text;
        }
        else
        {
            if (selProvince.selectedIndex > 0)
            {
                regionId = selProvince.options[selProvince.selectedIndex].value;
                regionName = selProvince.options[selProvince.selectedIndex].text;
            }
            else
            {
                if (selCountry.selectedIndex >= 0)
                {
                    regionId = selCountry.options[selCountry.selectedIndex].value;
                    regionName = selCountry.options[selCountry.selectedIndex].text;
                }
                else
                {
                    return;
                }
            }
        }
    }

    // 检查该地区是否已经存在
    exists = false;
    for (i = 0; i < document.forms['theForm'].elements.length; i++)
    {
      if (document.forms['theForm'].elements[i].type=="checkbox" && document.forms['theForm'].elements[i].name.substr(0, 6) == 'region')
      {
        if (document.forms['theForm'].elements[i].value == regionId)
        {
          exists = true;
          alert(region_exists);
          break;
        }
      }
    }

    // 创建checkbox
    if (!exists)
    {
      regionCell.innerHTML += "<input type='checkbox' name='regions[]' value='" + regionId + "' checked='true' /> " + regionName + "&nbsp;&nbsp;";
    }
}
function search_admin(){ 
	$.post("agency.php",{act:'search_admin',user_name:$("#user_name").val(),role_id:$("#role option:selected").val()},function(data){ 
		var html="";
		for(i=0;i<data.content.length;i++){ 
			html+="<option value='"+data.content[i].user_id+"'>";
			if(data.content[i].agency_id>0){ 
				html+="(*)";
			}
			html+=data.content[i].user_name+"</option>";
		}
		$('#search_admin_list').html(html);
	},'json');
}
function add_admin(){ 
	$user_id=parseInt($("#search_admin_list option:selected").val());
	$user_name=$("#search_admin_list option:selected").text();
	//判断是否已添加
	var is_add=false;
	$("#agency_admin_list input").each(function(){ 
		if($(this).val()==$user_id)is_add=true;
	});
	if(is_add){
		alert('已经添加了。');
		return;
	}
	if($user_id>0){ 
		var segment='<input type="checkbox" name="admins[]" value="'+$user_id+'" checked="checked" />'+$user_name+'&nbsp;&nbsp;';
		$("#agency_admin_list").append(segment);
	}
}
//-->
</script>
{/literal}
{include file="pagefooter.htm"}